package com.controller.frontdesk;

import com.bean.pojo.GoodsType;
import com.bean.vo.admin.Result;
import com.google.gson.Gson;
import com.service.frontdesk.GoodServiceImplement;
import com.service.frontdesk.UserServiceImplement;
import com.utils.GsonUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/api/mall/index/*")
public class TypeServlet extends HttpServlet {
    private Gson gson = GsonUtils.getGson();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String requestURI = request.getRequestURI();
        String action = requestURI.replace(request.getContextPath() + "/api/mall/index/", "");
        if ("getType".equals(action)){
            showTypes(request,response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }


    /**
     * 显示所有商品分类
     * @param request
     * @param response
     */
    private void showTypes(HttpServletRequest request, HttpServletResponse response) throws IOException {
        GoodServiceImplement goodServiceImplement = new GoodServiceImplement();
        List<GoodsType> goodsTypes = goodServiceImplement.showAllType();
        response.getWriter().println(gson.toJson(new Result(0,goodsTypes,null)));
    }
}
